import { Tag, Image } from "antd";
import { mapData } from "@/utils/mapData";
import { changeFormat } from "@/utils/format";
import defaultAvatar from "@/common/img/default_avatar.jpg";
import { formatBirth, formatYear } from "@/utils/format";
import IconMap from "@/components/IconMap";
/**
accountName: "letvpn"
avatar: "https://reactoa.hyfarsight.com/FrBl9IMFBoOS3a6tvN9DnjMSs_cK"
bankNumber: "123456789123456789"
education: 1
graduatedSchool: "天津大学"
hometown: "北京市朝阳区"
idNumber: "211302198305112819"
identity: 0
marriage: 0
onboardingTime: "2021-11-12T09:43:26.939Z"
salary: "4000"
 */

const Columns = ({ handleSave, userInfos, openReviewRecord, openDetailDialog }) => {
    const normalColumn = [
        {
            title: '姓名',
            dataIndex: 'userName',
            width: '200px',
            align: "center"
        },
        {
            title: '联系电话',
            dataIndex: 'mobile',
            width: '200px',
            align: "center"


        },
        {
            title: '职级描述',
            dataIndex: 'level',
            render(level) {
                return level?.levelDescription || "暂无职级描述"
            }
        },
        {
            title: '性别',
            dataIndex: 'gender',
            render(gender) {
                return <Tag>{gender === 1 ? "男" : "女"}</Tag>
            }
        },
        {
            title: '部门',
            dataIndex: 'department',
            render(data) {
                return data?.departmentName || "--"
            }
        },
        {
            title: '部门负责人',
            dataIndex: 'department',
            render(data) {
                return data?.departmentLeader?.userName || '---';
            }
        },
    ];

    const AdminsColumn = [
        {
            title: '姓名',
            dataIndex: 'userName',
            width: '200px',
            editable: true,
            align: "center",
            render(userName, data) {
                return <div
                    className="staff-detail-cur"
                >
                    <span>{userName}</span>
                    {/* 获取详情 */}
                    <span className="c-p" onClick={(e) => {
                        e.stopPropagation();
                        openDetailDialog(data._id);
                    }}>{IconMap.detail}</span>
                </div>
            }
        },
        {
            title: '联系电话',
            dataIndex: 'mobile',
            width: '200px',
            editable: true,
            align: "center"



        },
        {
            title: '职级描述',
            dataIndex: 'level',
            render(level) {
                return level?.levelDescription || "暂无职级描述"
            }
        },
        {
            title: '性别',
            dataIndex: 'gender',
            editable: true,
            render(gender) {
                return <Tag>{gender === 0 ? "男" : "女"}</Tag>
            }
        },
        {
            title: '部门',
            dataIndex: 'department',

            render(data) {
                return data?.departmentName || "--"
            }
        },
        {
            title: '部门负责人',
            dataIndex: 'department',

            render(data) {
                return data?.departmentLeader?.userName || '---';
            }
        },
        {
            title: '入职时间',
            dataIndex: 'onboardingTime',
            editable: true,
            render: (date) => changeFormat(date, 'YYYY-MM-DD'),
        },
        {
            title: '年龄',
            dataIndex: 'idNumber',
            editable: true,
            render: (idNumber) => formatYear(idNumber, 'age') + "岁",
        },
        {
            title: '头像',
            dataIndex: 'avatar',
            width: "50px",
            render: (avatar) => <Image src={avatar ? avatar : defaultAvatar} />,
        },
        {
            title: '籍贯',
            editable: true,
            dataIndex: 'hometown',
            render: (hometown) => hometown || '---',
        },
        {
            title: '学历',
            editable: true,
            dataIndex: 'education',
            render: (type) => <Tag> {mapData['education'][type]}</Tag>,
        },
        {
            title: '婚姻状况',
            editable: true,
            dataIndex: 'marriage',
            render: (type) => <Tag> {mapData['marriage'][type]}</Tag>,
        },
        {
            title: '生日',
            dataIndex: 'idNumber',
            editable: true,
            render: (id) => {
                const birthday = formatBirth(id).split("-");
                return `${birthday[0]} 年 ${birthday[1]} 月 ${birthday[2]} 日`
            },
        },
        {
            title: '银行卡',
            dataIndex: 'bankNumber',
            editable: true,
        },
        {
            title: '身份证号',
            editable: true,
            dataIndex: 'idNumber',
        },
        {
            title: '毕业院校',
            editable: true,
            dataIndex: 'graduatedSchool',
        },
        {
            title: "绩效考核",
            dataIndex: "redux",
            render(redux, data) {
                return <Tag className="c-p" onClick={() => {
                    console.log(data)
                    openReviewRecord({
                        type: "assessmentList",
                        interfaced: "getAssessmentList",
                        params: {
                            queryData: {
                                staffName: data._id
                            }
                        },
                        title: "绩效考核"
                    });
                }}>查看</Tag>
            }
        },
        {
            title: "奖惩记录",
            dataIndex: "redux",
            render(redux, data) {
                return <Tag className="c-p" onClick={() => {
                    openReviewRecord({
                        type: "rewardAndPunishment",
                        interfaced: "getrewardAndPunishmentList",
                        params: {
                            staffName: data._id
                        },
                        title: "奖惩记录"
                    });
                }}>查看</Tag>
            },
        },
        {
            title: "调薪记录",
            dataIndex: "redux",
            render(redux, data) {
                return <Tag className="c-p" onClick={() => {
                    openReviewRecord({
                        type: "salaryAdjustment",
                        interfaced: "getSalaryAdjustmentList",
                        params: {
                            staffName: data._id
                        },
                        title: "调薪记录"
                    });
                }}>查看</Tag>
            },
        }
    ];

    let columns = userInfos.identity === 1 ? AdminsColumn : normalColumn;

    columns = columns.map((col) => {
        if (!col.editable) {
            return col;
        }
        // 进行设置不同的类型进行判断
        let type = "";
        const SelectorArr = ["gender", "education", "marriage"];
        if (SelectorArr.includes(col.dataIndex)) {
            type = "SelectorIndex"
        } else if (col.dataIndex === "onboardingTime") {
            type = "dateIndex"
        } else {
            type = "InputIndex"
        }
        return {
            ...col,
            onCell: (record) => ({
                record,
                type,
                editable: col.editable,
                dataIndex: col.dataIndex,
                title: col.title,
                handleSave,
            }),
        };
    });
    return columns;
}

export default Columns;